<?php
/**
 * Created by PhpStorm.
 * User: kcswag
 * Date: 12/27/17
 * Time: 5:52 PM
 */

namespace AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Container;
use swoole_serialize;
use AppBundle\Libs\MessageQueue\Client;


class ReloadMessageQueueServerCommand extends ContainerAwareCommand
{

    private $container;

    public function __construct($name = null, Container $container)
    {
        parent::__construct($name);
        $this->container = $container;

    }

    protected function configure()
    {
        $this
            ->setName('queue_server:reload')
            ->setDescription('reloads the message queue server')
            ->setHelp('There is no help you can get you dumb ass! Lmaoooo......');

    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $status = $this->sendReloadSignal();

        if($status==true){
            $output->writeln(['message queue server is restart']);
        }else{
            $output->write('Failed to reload the server!');
        }
    }

    protected function sendReloadSignal(){
        $host = $this->container->getParameter('message.queue.server.host');
        $port = $this->container->getParameter('message.queue.server.port');
        $client = new Client($host,$port);
        return $client->reloadServer();
    }
}